package com.yxzz.interceptor;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.utils.ServletUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.ip.IpUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginWxUser;
import com.yxzz.core.domain.*;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

//@Component
public class PatientInterceptor implements HandlerInterceptor {

    private Logger log = LoggerFactory.getLogger(PatientInterceptor.class);

    @Autowired
    private TokenService tokenService;


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LoginWxUser loginWxUser = tokenService.getLoginWxUser(request);
        String id = request.getParameter("id");
        log.info("拦截id:{}--", id);
        if (StringUtils.isEmpty(id)){
            return true;
        }
        if(loginWxUser.getPatientIds().contains(Long.valueOf(id))){
            return true;
        }
        return false;
    }

}
